package com.ls.guava;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Ordering;

public class Employee implements Comparable {
    private String name;
    private Integer age;
    private String job;

   public Employee(String name,int age){
	   this.age=age;
	   this.name=name;
	   this.job="job-"+name;
   }

    public int compareTo(Employee other) {
        return ComparisonChain.start()
        // 以英文字母(从a到z)的自然顺序，NULL值放在最后
            .compare(this.name, other.name, Ordering.natural().nullsLast())
        // 以数字的反序(从大到小)，NULL值处于最后
            .compare(this.age, other.age, Ordering.natural().reverse().nullsLast())
            .compare(this.job, other.job, Ordering.natural().nullsLast())
            .result();
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(name, age, job);
    }

    @Override
    public String toString () {
        return MoreObjects.toStringHelper(this)
            .omitNullValues()
            .add("name", name)
            .add("age", age)
            .add("job", job)
            .toString();
    }

	@Override
	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		return 0;
	}
}